﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Semantics;

namespace Semantics.Example.GraphExample
{
    public partial class GraphForm : Form
    {
        public GraphForm()
        {
            InitializeComponent();
        }

        private void GraphForm_Load(object sender, EventArgs e)
        {
        }

        void SetGraph()
        {
            Graph graph = new Graph();
            Node node1 = new Node("西太平洋大学");
            graph.EnrollNode(node1);
            Node node2 = new Node("唐骏");
            graph.EnrollNode(node2);
            Node node3 = new Node("学位");
            graph.EnrollNode(node3);
            Node node4 = new Node("博士");
            graph.EnrollNode(node4);
            Node node5 = new Node("学校");
            graph.EnrollNode(node5);
            Edge edge1 = Edge.ConnectNode(node2, node3, node4);
            graph.EnrollEdge(edge1);
            Edge edge2 = Edge.ConnectNode(node4, node5, node1);
            graph.EnrollEdge(edge2);
            this.graphControl1.Graph = graph;
        }

        private void toolStripButtonFillGraph_Click(object sender, EventArgs e)
        {
            this.SetGraph();
        }
        private void toolStripButtonOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "Labeled Graph File(*.sn)|*.sn";
            if (dlg.ShowDialog() != DialogResult.OK)
                return;
            this.graphControl1.Graph=Graph.Read(dlg.FileName);
        }

        private void toolStripButtonSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "Labeled Graph File(*.sn)|*.sn";
            if (dlg.ShowDialog() != DialogResult.OK)
                return;
            try
            {
                this.graphControl1.Graph.Write(dlg.FileName);
            }
            catch (System.Exception exp)
            {
                MessageBox.Show(this, exp.Message);
            }
        }

    }
}
